package cn._2dland.gae.httpclient;

import cn._2dland.gae.httpclient.method.HttpMethod;

/**
 * Simple HttpClient For GAE/J
 */
public class HttpClient {
	private HttpClientParams params;
	private HttpCookie cookie = new HttpCookie();

	public HttpClient() {
		params = new HttpClientParams();
	}

	public HttpClient(HttpClientParams params) {
		this.params = params;
	}

	public HttpClientParams getParams() {
		return this.params;
	}

	public int executeMethod(HttpMethod method) {
		int respCode = 0;
		try {
			method.getParams().merge(params);
			// 设置cookie
			method.addRequestHeader("Cookie", cookie.toString());
			respCode = method.execute();
			// 保存cookie
			cookie.addCookies(method.getCookies());
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return respCode;
	}
}
